<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
</head>

<body>
    <script>
        //ES6 箭头函数 (=>)定义函数
        const fn = (a, b) => {
            return a + b
        }
        let res = fn(6, 6)
        console.log(res);


        //箭头函数中
        //1.this是静态的 ,this始终指向函数声明时所在作用域下的this的值
        function TEST1() {
            console.log(this);

        }

        let TEST2 = () => {
            console.log(this);
            //目前在全局作用域 this指向window
        }

        // 设置window对象的name
        window.name = "全局对象的name"
        const school = {
            name: "局部作用域的name"
        }

        //调用
        // TEST1()  window
        // TEST2()  window


        //call方法调用
        TEST1.call(school)//指向school的name
        TEST2.call(school)//全局window

        //2.不能作为构造实例化对象
        let Person = (name, age) => {
            this.name = name,
                this.age = age
        }

        // let Human = new Person('lili', 20)
        // console.log(Human);//Person is not a constructor


        // 3.函数没有arguments参数
        let includes = () => {
            console.log(arguments);
        }

        // includes(1, 2, 3, 4, 5, 6) 
        // arguments is not defined


        // 4.箭头函数简写
        // (1)省略小括号,当形参有且只有一个
        // let add = num => {
        //     return num + num
        // }
        // console.log(add(1))//2);

        // (2)省略花括号 此时return必须省略 语句结果就是返回值
        let pow = (num) => num * num

        console.log(pow(9));

    </script>
</body>

</html>